package com.zjp.dataFormat.controller;

import cn.hutool.core.collection.CollUtil;
import com.zjp.dataFormat.annotation.RangeTime;
import com.zjp.dataFormat.enums.UserFormatEnum;
import com.zjp.dataFormat.pojo.Order;
import com.zjp.dataFormat.pojo.common.CommonTimeQuery;
import com.zjp.dataFormat.service.OrderService;
import com.zjp.dataFormat.service.UserService;
import com.zjp.dataFormat.service.rangeTime.RangeTimeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("order")
public class OrderController {
    private final OrderService orderService;
    private final UserService userService;
    private final RangeTimeService rangeTimeService;


    public OrderController(OrderService orderService, UserService userService,
                           RangeTimeService rangeTimeService) {
        this.orderService = orderService;
        this.userService = userService;
        this.rangeTimeService = rangeTimeService;
    }

    @GetMapping("list")
    @RangeTime
    public ResponseEntity<List<Order>> list(CommonTimeQuery query) {
        List<Order> orders = orderService.listOrder(9);
        if (CollUtil.isNotEmpty(orders)) {
            List<Long> ids = orders.stream().map(Order::getUserId).collect(Collectors.toList());
            userService.format2(orders, ids, UserFormatEnum.INFO);
        }
        return ResponseEntity.ok(orders);

    }
}
